<?php
/*
 * 活动收藏
 */
namespace app\admin\model\member;

use think\Db;
use think\Model;


class ActivityCollect extends Model
{


    // 表名
    protected $table = 'activity_collect';//活动收藏表
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'ctime';
    protected $updateTime = 'utime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];


    public function activity()
    {
        //return $this->belongsTo('test', 'category_id')->field("name as scName,id,category_id as pcid");
        return $this->belongsTo('app\admin\model\vactivities\Activity', 'activity_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    /*
     * 查找此活动是否被收藏
     */
    public static function IsCollectById($aid,$uid){

        if(empty($aid) || empty($uid)){
            return false;
        }
        $map['activity_id'] = $aid;
        $map['uid'] = $uid;
        $r = Db::name('activity_collect')->where($map)->find();
        if($r)
            return true;
        else
            return false;
    }

    /*
     * 查找某人的收藏数量
     */

    public static function CollectCnt($uid){
        $map['uid'] = $uid;
        $cnt = Db::name('activity_collect')->where($map)->count();
        if($cnt > 0)
            return $cnt;
        else
            return 0;
    }
}
